<?php

namespace common\models\work;

use Yii;

/**
 * This is the model class for table "{{%category}}".
 *
 * @property int $id
 * @property int $parent_id 父级项目ID
 * @property string $name 项目名称
 * @property string $index 索引序号
 * @property string $description 描述/备注
 * @property int $inscene 现场检查
 * @property int $indata 资料检查
 * @property int $method 检查方式
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class Category extends \common\db\ActiveRecord {

    /**
     * 状态
     */
    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%category}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['parent_id', 'inscene', 'indata', 'method', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['name'], 'required'],
            [['name', 'index', 'description'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'parent_id' => '父级项目ID',
            'name' => '项目名称',
            'index' => '索引序号',
            'description' => '描述/备注',
            'inscene' => '现场检查',
            'indata' => '资料检查',
            'method' => '检查方式',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function getParent() {
        return $this->hasOne(static::class, ['id' => 'parent_id']);
    }

    /**
     * {@inheritdoc}
     */
    public function getChildren() {
        return $this->hasMany(static::class, ['parent_id' => 'id']);
    }

    /**
     * {@inheritdoc}
     */
    public function getActiveChildren() {
        return $this->getChildren()->active();
    }

}
